{{ $Deliver := .Deliver }}
{{ $isHome := .isHome }}
<div class="post-meta">
    {{ if and $Deliver.Site.Params.displayPublishedDate (not $Deliver.PublishDate.IsZero) }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.publishedDateIcon) "icon" "icon post-meta-icon" }}
        {{ printf `<time datetime="%s" class="post-meta-item published">%s&nbsp;%s</time>` ($Deliver.PublishDate.Format "2006-01-02T15:04:05-07:00") $icon ($Deliver.PublishDate.Format $Deliver.Site.Params.postMetaDateFormat) | safeHTML }}
    {{ end }}
    {{ if and $Deliver.Site.Params.displayModifiedDate (not $Deliver.Lastmod.IsZero) }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.modifiedDateIcon) "icon" "icon post-meta-icon" }}
        {{ printf `<time datetime="%s" class="post-meta-item modified">%s&nbsp;%s</time>` ($Deliver.Lastmod.Format "2006-01-02T15:04:05-07:00") $icon ($Deliver.Lastmod.Format $Deliver.Site.Params.postMetaDateFormat) | safeHTML }}
    {{ end }}
    {{ if and $Deliver.Site.Params.displayExpiredDate (not $Deliver.ExpiryDate.IsZero) }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.expiredDateIcon) "icon" "icon post-meta-icon" }}
        {{ printf `<time datetime="%s" class="post-meta-item expired">%s&nbsp;%s</time>` ($Deliver.ExpiryDate.Format "2006-01-02T15:04:05-07:00") $icon ($Deliver.ExpiryDate.Format $Deliver.Site.Params.postMetaDateFormat) | safeHTML }}
    {{ end }}
    {{ if $Deliver.Site.Params.displayCategory }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.categoryIcon) "icon" "icon post-meta-icon" | safeHTML }}
        {{ if and (eq $Deliver.Site.Params.categoryBy "sections") (in $Deliver.Site.Params.mainSections $Deliver.Section) }}
            {{ $sections := split (strings.TrimSuffix "/" ($Deliver.File.Dir | default $Deliver.Section)) "/" }}
            {{ with $sections }}
                {{ $Deliver.Scratch.Delete "sectionsDirMeta" }}
                {{ $Deliver.Scratch.Delete "sectionsMeta" }}
                {{ $Deliver.Scratch.Set "index" 0 }}
                {{ range $sections }}
                    {{ $section := . }}
                    {{ $Deliver.Scratch.Add "sectionsDirMeta" (printf `/%s` $section) }}
                    {{ with $Deliver.Site.GetPage ($Deliver.Scratch.Get "sectionsDirMeta") }}
                        {{ if (eq .Kind "section") }}
                            {{ $Deliver.Scratch.SetInMap "sectionsMeta" (printf `%s/%s` (string ($Deliver.Scratch.Get "index")) .RelPermalink) (.LinkTitle | default $section) }}
                            {{ $Deliver.Scratch.Set "index" (add ($Deliver.Scratch.Get "index") 1) }}
                        {{ end }}
                    {{ end }}
                {{ end }}
            {{ end }}
            {{ $sections := $Deliver.Scratch.Get "sectionsMeta" }}
            {{ with $sections }}
                {{ $length := (sub (len $sections) 1) }}
                <span class="post-meta-item category">
                    {{- printf `%s&nbsp;` $icon | safeHTML -}}
                    {{- range $link, $title := $sections -}}
                        {{- $index := $link | replaceRE `(\d+)/.+` `$1` | int -}}
                        {{- if lt $index $length -}}
                            {{- $Deliver.Scratch.Set "delimiter" ($Deliver.Site.Params.categoryDelimiter | default "/") -}}
                        {{- else -}}
                            {{- $Deliver.Scratch.Set "delimiter" "" -}}
                        {{- end -}}
                        {{- $delimiter := ($Deliver.Scratch.Get "delimiter") -}}
                        {{- printf `<a href="%s" class="category-link">%s</a>%s` ($link | replaceRE `\d+/(.+)` `$1`) $title $delimiter | safeHTML -}}
                    {{- end -}}
                </span>
            {{ end }}
        {{ end }}
        {{ if eq $Deliver.Site.Params.categoryBy "categories" }}
            {{ with $Deliver.Params.categories }}
                {{ $length := sub (len .) 1 }}
                <span class="post-meta-item category">
                    {{- printf `%s&nbsp;` $icon | safeHTML -}}
                    {{- range $index, $category := . -}}
                        {{- $url := urls.Parse ($category | urlize) -}}
                        {{- $path := $url.Path -}}
                        {{- if lt $index $length -}}
                            {{- $Deliver.Scratch.Set "delimiter" ($Deliver.Site.Params.categoryDelimiter | default "/") -}}
                        {{- else -}}
                            {{- $Deliver.Scratch.Set "delimiter" "" -}}
                        {{- end -}}
                        {{- $delimiter := ($Deliver.Scratch.Get "delimiter") -}}
                        {{- with $Deliver.Site.GetPage (printf `/categories/%s` $path) -}}
                            {{- printf `<a href="%s" class="category-link">%s</a>%s` .RelPermalink (.LinkTitle | default $category) $delimiter | safeHTML -}}
                        {{- end -}}
                    {{- end -}}
                </span>
            {{ end }}
        {{ end }}
    {{ end }}
    {{ if $Deliver.Site.Params.displayWordCount }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.wordCountIcon) "icon" "icon post-meta-icon" | safeHTML }}
        <span class="post-meta-item wordcount">{{ $icon }}&nbsp;{{ $Deliver.WordCount }}</span>
    {{ end }}
    {{ if $Deliver.Site.Params.displayReadingTime }}
        {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.readingTimeIcon) "icon" "icon post-meta-icon" | safeHTML }}
        <span class="post-meta-item reading-time">{{ $icon }}&nbsp;{{ $Deliver.ReadingTime }}&nbsp;{{ i18n "minute" $Deliver.ReadingTime }}</span>
    {{ end }}
    {{ if and $Deliver.Site.Params.displayBusuanziPagePV (eq hugo.Environment "production") }}
        {{ if not $isHome }}
            {{ $icon := replace (index $Deliver.Site.Data.SVG $Deliver.Site.Params.busuanziPagePVIcon) "icon" "icon post-meta-icon" | safeHTML }}
            <span class="post-meta-item busuanzi-page-pv" id="busuanzi_container_page_pv">{{ $icon }}&nbsp;<span id="busuanzi_value_page_pv"></span></span>
        {{ end }}
    {{ end }}
</div>